using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MouseGestures;
using System.Resources;
using System.Reflection;

namespace MouseGesturesTest {
  public partial class MainForm : Form {
    private PictureBox[] mouseGestureDisplay;

    public MainForm() {
      InitializeComponent();

      mouseGestureDisplay = new PictureBox[16];

			pbUp.Tag = "U";
			pbRight.Tag = "R";
			pbDown.Tag = "D";
			pbLeft.Tag = "L";

			pbUpRight.Tag = "UR";
			pbUpDown.Tag = "UD";
			pbUpLeft.Tag = "UL";

			pbRightUp.Tag = "RU";
			pbRightDown.Tag = "RD";
			pbRightLeft.Tag = "RL";

			pbDownUp.Tag = "DU";
			pbDownRight.Tag = "DR";
			pbDownLeft.Tag = "DL";

			pbLeftUp.Tag = "LU";
			pbLeftRight.Tag = "LR";
			pbLeftDown.Tag = "LD";

      mouseGestureDisplay[0] = pbUp;
      mouseGestureDisplay[1] = pbRight;
      mouseGestureDisplay[2] = pbDown;
      mouseGestureDisplay[3] = pbLeft;

      mouseGestureDisplay[4] = pbUpRight;
      mouseGestureDisplay[5] = pbUpDown;
      mouseGestureDisplay[6] = pbUpLeft;

      mouseGestureDisplay[7] = pbRightUp;
      mouseGestureDisplay[8] = pbRightDown;
      mouseGestureDisplay[9] = pbRightLeft;

      mouseGestureDisplay[10] = pbDownUp;
      mouseGestureDisplay[11] = pbDownRight;
      mouseGestureDisplay[12] = pbDownLeft;

      mouseGestureDisplay[13] = pbLeftUp;
      mouseGestureDisplay[14] = pbLeftRight;
      mouseGestureDisplay[15] = pbLeftDown;
    }

    private void timerReset_Tick(object sender, EventArgs e) {
      //resets images to normal
      ResetImages();
      timerReset.Stop();
    }

    private void ResetImages() {
      foreach ( PictureBox pb in mouseGestureDisplay ) {
        pb.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(
          getResourceName((string)pb.Tag, false)));
      }
    }

    //Build full name of the resource
		private string getResourceName(string gestureName, bool activeImage) {
      string active = "";
      if ( activeImage )
        active = "A";

      return "MouseGesturesTest.Images." + gestureName + active + ".png";
    }

    private void mouseGesturesTest_Gesture(object sender, MouseGestureEventArgs e) {
      foreach ( PictureBox pb in mouseGestureDisplay ) {
        if ( ( string )pb.Tag == e.Gesture.ToString() ) {
          //load image from the resources
          pb.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(
    getResourceName(e.Gesture.Motions, true)));

          timerReset.Start();
          return;
        }
      }
    }

    private void MainForm_Load(object sender, EventArgs e) {
      ResetImages();
    }


  }
}